import logging
from dataclasses import dataclass
from dotenv import load_dotenv
import os, sys
from typing import Optional
from enum import Enum, auto
from app.core.config.__logging__ import LOG_LEVELS, LOG_FILE


class Platform(Enum):
    WINDOWS = "Windows"
    MAC = "Mac"
    LINUX = "Linux"
    UNKNOW = "Unknow"


class ScanFlexMode(Enum):
    STRICT = "Strict"
    LOOSE = "Loose"


class MockResponseType(Enum):
    MockData_200 = 200
    MockData_400 = 400
    MockData_406 = 406
    MockData_422 = 422
    MockData_201 = 201


def __which_platform():
    if sys.platform.startswith('win'):
        return Platform.WINDOWS
    elif sys.platform.startswith('linux'):
        return Platform.LINUX
    elif sys.platform.startswith('darwin'):
        return Platform.MAC
    else:
        return Platform.UNKNOW


def __which_file_split_symbol():
    if __which_platform() == Platform.WINDOWS:
        return '\\'
    else:
        return '/'


# 加载.env文件
load_dotenv()


@dataclass()
class Setting:
    project_name: str
    api_v1: str
    env_file: str
    env: str
    platform: Platform
    file_split_symbol: str
    log_level: str
    log_file: str
    san_flex_timeout: int
    db_url: str
    default_gateway: Optional[str]
    scan_flex_mode: ScanFlexMode
    version: str
    use_mock: bool
    mock_locale: str
    mock_type: MockResponseType


setting = Setting(
    # project
    project_name="opentrons-endpoint",
    version="1.0.3",
    api_v1='/api/v1',
    env_file='.env',
    env=os.getenv("ENV"),
    # mock
    use_mock=True if os.getenv("IS_SIMULATING") == "True" else False,
    mock_locale="zh_CN",
    mock_type=MockResponseType.MockData_200,
    # general
    platform=__which_platform(),
    file_split_symbol=__which_file_split_symbol(),
    # log
    log_level=LOG_LEVELS.get(logging.INFO),
    log_file=LOG_FILE,
    # database
    db_url=os.getenv("DATABASE"),
    # scan robot
    san_flex_timeout=5,
    default_gateway="192.168.6.1",
    scan_flex_mode=ScanFlexMode.LOOSE
)
